import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

// https://webpack.js.org/guides/dependency-management/#requirecontext
const modulesFiles = require.context('./modules', true, /\.js$/)

// you do not need `import app from './modules/app'`
// it will auto require all vuex module from modules file
const modules = modulesFiles.keys().reduce((modules, modulePath) => {
    // set './app.js' => 'app'
    const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, '$1')
    const value = modulesFiles(modulePath)
    modules[moduleName] = value.default
    return modules
}, {})

// let now = new Date()
// let startTime = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate())).toISOString().slice(0, 10)
// let endTime = new Date(Date.UTC(now.getFullYear(), now.getMonth(), now.getDate()+1)).toISOString().slice(0, 10)

const state = {
    group: {
        xzxm: null,
    },
    filters: {
        time: '',
        dateTimes: [],
        departmentId: '',
        projectId: '',
        departList: [],
        projectName: '',
        radio: true
    },
    allDepartmentList: [],
    standardKPI: {},
    entry: '',
    entryItem: {},
    userEntry: '',
    scoreEntry: '',
    macEntry: '',
    // resourceReportForCarEntry: '',
    projectEntry: '',
    proChangeEntry: '',
    resourceEntry: '',
    proMainEntry: '',
    basicDataEntry: '',
    chooseList: {
        time: '',
        dateTimes: [],
        groupId: '',
        groupValue: '',
        radio: 1,
        monthKpi: ''
    },
    dataChoose: {
        radio: 1,
        selectId: '',
        selectName: '',
        time: '',
        dateTimes: '',
        projectId: '',
        groupId: '',
        solveStatus: false,
        dataSolveStatus: false,
    }
    // pdfStatus: false,
    // inputStatus: false
}

const mutations = {
    setGroupXzxm: state => {
        state.group.xzxm = Math.random()
    },
    setParams: (state, params) => {
        state.filters = params
    },
    setAll: (state, list) => {
        state.allDepartmentList = list
    },
    setKpi: (state, standardKPI) => {
        state.standardKPI = standardKPI
    },
    setChoose: (state, chooseList) => {
        state.chooseList = chooseList
    },
    setEntry: (state, entry) => {
        state.entry = entry
    },
    setEntryItem: (state, entryItem) => {
        state.entryItem = entryItem
    },
    setUserEntry: (state, userEntry) => {
        state.userEntry = userEntry
    },
    setScoreEntry: (state, scoreEntry) => {
        state.scoreEntry = scoreEntry
    },
    setDataChoose: (state, dataChoose) => {
            state.dataChoose = dataChoose
        },
        // setpdfStatus: (state, pdfStatus) => {
        //   state.pdfStatus = pdfStatus
        // },
        // setinputStatus: (state, inputStatus) => {
        //   state.inputStatus = inputStatus
        // }
    setMacEntry: (state, macEntry) => {
        state.macEntry = macEntry
    },
    // setResourceReportForCarEntry: (state, resourceReportForCarEntry) => {
    //     state.resourceReportForCarEntry = resourceReportForCarEntry
    // },
    setProjectEntry: (state, projectEntry) => {
        state.projectEntry = projectEntry
    },
    setProChangeEntry: (state, proChangeEntry) => {
        state.proChangeEntry = proChangeEntry
    },
    setResourceEntry: (state, resourceEntry) => {
        state.resourceEntry = resourceEntry
    },
    setProMainEntry: (state, proMainEntry) => {
        state.proMainEntry = proMainEntry
    },
    setBasicDataEntry: (state, basicDataEntry) => {
        state.basicDataEntry = basicDataEntry
    },
}


const store = new Vuex.Store({
    modules,
    state,
    mutations,
    getters
})

export default store
